
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class Window extends JFrame {
    
    private static final double VERSION_NUMBER = 0.1;
    private JTextArea display;
    private JTextField textField;
    private JComboBox typeChoice;
    private JComboBox priorityChoice;
    private JButton addButton;
    private ArrayList<Idea> ideas;

    public Window(){

        ideas = new ArrayList<Idea>();

        setSize(500,300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("Ideas Tracker version " + VERSION_NUMBER);

        // window is a JFrame
        // JFrames are BorderLayout by default
        // JPanels are FlowLayout by default

        // create the containers - two panels TOP and CENTER
        JPanel topPanel = new JPanel();
        topPanel.setBackground(Color.YELLOW);
        JPanel centerPanel = new JPanel();
        centerPanel.setBackground(Color.GREEN);
        
        // add the panels to the frame
        add(topPanel, BorderLayout.NORTH);
        add(centerPanel, BorderLayout.CENTER);

        // create the UI elements
        display = new JTextArea();

        textField = new JTextField(10);
        typeChoice = new JComboBox(TypeValue.values());
        priorityChoice = new JComboBox(PriorityValue.values());

        addButton = new JButton("add");

        // add the UI elements to the Panels
        topPanel.add(textField);
        topPanel.add(typeChoice);
        topPanel.add(priorityChoice);
        topPanel.add(addButton);
        

        centerPanel.add(display);


        // setup the event for the button

        addButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e){

                //create new
                PriorityValue priorityValue = (PriorityValue) priorityChoice.getSelectedItem();
                TypeValue typeValue = (TypeValue) typeChoice.getSelectedItem();

                Idea idea = new Idea(textField.getText(), priorityValue, typeValue);

                System.out.println("idea " + idea);

                ideas.add(idea);

                StringBuilder buff = new StringBuilder();
                for (Idea currentIdea : ideas) {
                    buff.append(currentIdea);
                    buff.append("\n");

                }
                display.setText(buff.toString().trim());
            }

            });

    }



    public static void main(String[] args) {
        Window window = new Window();


        window.setVisible(true);
    }


}
